#!/usr/bin/env python
# coding:utf-8
"""
@Version: V1.0
@Author: willson
@License: Apache Licence
@Contact: willson.wu@goertek.com
@Site: goertek.com
@Software: PyCharm
@File: demo.py
@Time: 19-8-21 下午2:07
"""
from datetime import timedelta

import web
from minio import Minio
from minio.error import ResponseError

urls = (
    '/', 'hello'
)

app = web.application(urls, globals())


class hello:
    def GET(self):
        return """"""



def func():
    s3Client = Minio('10.10.192.18:9001',
                     access_key='minio',
                     secret_key='minio123', secure=False)

    buckets_list = s3Client.list_buckets()
    for item in buckets_list:
        print(item.name)

    # try:
    #     data = s3Client.get_object('qqqq', '部门代码.png')
    #     print(data.stream(32 * 1024))
    #     # with open('my-testfile.png', 'wb') as file_data:
    #     #     for d in data.stream(32*1024):
    #     #         file_data.write(d)
    # except ResponseError as err:
    #     print(err)

    # try:
    #     print(s3Client.presigned_get_object('images', '部门代码.png', expires=timedelta(days=2)))
    # # Response error is still possible since internally presigned does get bucket location.
    # except ResponseError as err:
    #     print(err)
    # pass

    # try:
    #     s3Client.remove_object('qqqq', 'qqqq/x/')
    # except ResponseError as err:
    #     print(err)

    objects = s3Client.list_objects_v2('test',recursive=True,prefix='iu/')
    for obj in objects:
        print(obj.bucket_name, obj.object_name, obj.last_modified,
              obj.etag, obj.size, obj.content_type,obj.is_dir)
        try:
            s3Client.remove_object('test', obj.object_name)
        except ResponseError as err:
            print(err)



class Main():
    def __init__(self):
        pass


if __name__ == "__main__":
    # app.run()
    func()